package com.shop.cereshop.business.dl.logic.controller;

import com.shop.cereshop.business.dl.logic.domain.CereShopAnnouncement;
import com.shop.cereshop.business.dl.logic.service.CereShopAnnouncementService;
import com.shop.cereshop.business.dl.logic.utils.ResultInfo;
import com.shop.cereshop.commons.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 况鑫威
 * @Date: 2021/7/22
 * @Time: 16:17
 * @ClassName: CereShopAnnouncementController
 * @Description: com.shop.cereshop.business.dl.logic.controller
 */
@RestController
@RequestMapping("announcement")
public class CereShopAnnouncementController {
    @Autowired
    private CereShopAnnouncementService cereShopAnnouncementService;

    /**
     * 功能描述: 添加公告
     * @Param: [cereShopAnnouncement]
     * @return: com.shop.cereshop.business.dl.logic.utils.ResultInfo<?>
     * @Author: 况鑫威
     * @Date: 2021/7/22
     * @Time: 16:26
     */
    @PostMapping("insertAnnouncement")
    public ResultInfo<?> insertAnnouncement(CereShopAnnouncement cereShopAnnouncement) {
        cereShopAnnouncement.setCreateTime(TimeUtils.yyMMddHHmmss());
        if(cereShopAnnouncementService.insertSelective(cereShopAnnouncement) > 0){
            return new ResultInfo<>();
        }
        return ResultInfo.error();
    }

    /**
     * 功能描述: 所有公告
     * @Param: []
     * @return: com.shop.cereshop.business.dl.logic.utils.ResultInfo<?>
     * @Author: 况鑫威
     * @Date: 2021/7/22
     * @Time: 16:34
     */
    @PostMapping("getAnnouncements")
    public ResultInfo<?> getAnnouncements(String announcementType,
                                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "row", defaultValue = "10") Integer row) {
        return new ResultInfo<>(cereShopAnnouncementService.getAnnouncements(announcementType, page, row));
    }

    /**
     * 功能描述: 单个公告
     * @Param: []
     * @return: com.shop.cereshop.business.dl.logic.utils.ResultInfo<?>
     * @Author: 况鑫威
     * @Date: 2021/7/22
     * @Time: 16:34
     */
    @PostMapping("getSelectByPrimaryKey")
    public ResultInfo<?> selectByPrimaryKey(Long announcementId) {
        return new ResultInfo<>(cereShopAnnouncementService.selectByPrimaryKey(announcementId));
    }

    /**
     * 功能描述: 修改公告
     * @Param: [cereShopAnnouncement]
     * @return: com.shop.cereshop.business.dl.logic.utils.ResultInfo<?>
     * @Author: 况鑫威
     * @Date: 2021/7/22
     * @Time: 16:26
     */
    @PostMapping("updateAnnouncement")
    public ResultInfo<?> updateAnnouncement(CereShopAnnouncement cereShopAnnouncement) {
        if(cereShopAnnouncementService.updateByPrimaryKeySelective(cereShopAnnouncement) > 0){
            return new ResultInfo<>();
        }
        return ResultInfo.error();
    }

    /**
     * 功能描述: 删除公告
     * @Param: [announcementId]
     * @return: com.shop.cereshop.business.dl.logic.utils.ResultInfo<?>
     * @Author: 况鑫威
     * @Date: 2021/7/22
     * @Time: 16:26
     */
    @PostMapping("deleteAnnouncement")
    public ResultInfo<?> deleteAnnouncement(Long announcementId) {
        if(cereShopAnnouncementService.deleteByPrimaryKey(announcementId) > 0){
            return new ResultInfo<>();
        }
        return ResultInfo.error();
    }


}
